//
//  SaleLeftListView.m
//  SmallEasyLife
//
//  Created by qianfeng on 15/10/23.
//  Copyright © 2015年 GXK. All rights reserved.
//

#import "SaleLeftListView.h"
#import "SaleBDCell.h"
#import "Masonry.h"
#import "BDNodeModel.h"

@interface SaleLeftListView ()<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic, weak) UITableView * tableView;

@end


@implementation SaleLeftListView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        self.tableView.delegate = self;
        self.tableView.dataSource = self;
        
        [self.tableView registerNib:[UINib nibWithNibName:@"SaleBDCell" bundle:nil] forCellReuseIdentifier:@"BDCell"];
    }
    return self;
}

- (UITableView *)tableView
{
    if (_tableView == nil) {
        UITableView * tableView = [[UITableView alloc] initWithFrame:self.frame style:UITableViewStylePlain];
        _tableView = tableView;
        [self addSubview:tableView];
        
        [tableView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.mas_top);
            make.left.equalTo(self.mas_left);
            make.width.equalTo(self.mas_width);
            make.height.equalTo(self.mas_height);
        }];
    }
    return _tableView;
}
- (void)setDataArray:(NSArray *)dataArray
{
    if (_dataArray != dataArray) {
        _dataArray = dataArray;
        [self.tableView reloadData];
    }
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataArray.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    BDNodeModel * nodeModel = self.dataArray[indexPath.row];
    return nodeModel.contentHeight;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//    NSLog(@"row did selected -> %lu",indexPath.row);
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    SaleBDCell * cell = [tableView dequeueReusableCellWithIdentifier:@"BDCell" forIndexPath:indexPath];
    BDNodeModel * nodeModel = self.dataArray[indexPath.row];
    cell.model = nodeModel;
    
    cell.ownerViewController = self.ownerViewController;
    
    return cell;
}


@end
